<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template_u extends CI_Controller {

        public function __construct()
        {
            parent::__construct();
        }
	public function index()
	{
//                $this->load->helper('html');
//                $this->load->view("template_u/template_u_header");
                $this->homepage("home");
//                $this->load->view("template_u/template_u_footer");
	}
//        public function admin($file,$value=0,$value1=0,$value2=1)
//        {
//            $this->load->helper('html');
//            $this->load->helper('date');     
//            $this->load->helper('string');
//            $this->load->view("template_u/template_u_header");    
//            $data['access_admin']    = true;
//            $data['select_menu']    = $value1;   
//            $data['key']       = $value;             
////            echo "file: ".$file;            
//            if($file=="checkadmin")
//            {
//                if(isset($_POST['username']) && isset($_POST['password'])){
//                    $rs    = $this->homepage_model->getCheckAdmin($_POST['username'],$_POST['password']);
//                    $data["r"]     = $rs->result_array();
//                    $data["r_num"] = $rs->num_rows();
//    //                echo $_POST['username']." , ".$_POST['password'];
//                    $data['user_in']   =   $_POST['username'];
//                    $data['pass_in']   =   $_POST['password'];
////                    $data['key']       = $value;
//                    $this->load->view("backend/admin/$file",$data);   
//                }else{
//                    $this->load->view("backend/admin/login");
//                }
//            }
//            else 
//            if($file=="admin")
//            {
////                $data['select_menu']    = $value1;   
////                $data['key']       = $value;      
//                if($value1=="show"){
////                    $data['key']       = $value;                    
//                    $rs = $this->homepage_model->getNews($value2,20);
//                    $data['r']      = $rs->result_array();
//                    $data['r_num']  = $rs->num_rows();
//                    $this->load->view("backend/admin/$file",$data);
//                }else if($value1=="add"){              
//                    $this->load->view("backend/admin/$file",$data);
//                }else if($value1=="add_news"){
////                $data['key']       = $value;
////                $data['select_menu']    = $value1;                    
////                    $this->load->library('upload');
//                    $headnews   =   $_POST['headnews'];
//                    $headline   =   $_POST['headline'];
//                    $detail     =   $_POST['detail'];
//                    $linkurl    =   $_POST['linkurl'];
////                    $data['pic_news']   =   $_POST['pic_news'];
//
//		$config['upload_path'] = './assets/images/news';
//                $config['allowed_types'] = 'jpg|jpeg|gif|png';
//		$config['max_size']	= '100';
//		$config['max_width']  = '1024';
//		$config['max_height']  = '768';
//                $config['overwrite'] = TRUE;            
//
//		$this->load->library('upload', $config);
//
//		if ( ! $this->upload->do_upload())
//		{
//			$data['error'] = array('error' => $this->upload->display_errors());
//
////			$this->load->view('backend/admin/admin', $data);
//		}
//		else
//		{
//			$data['upload_data']    =   $this->upload->data();
//                        $data['select_menu']    =   "add_success";
//                        $rs = $this->db->query("SELECT id_new FROM NEWS ORDER BY ID_NEW DESC LIMIT 1");
//                        $id_new     = $rs->result_array();
//                        foreach($id_new as $max_id){
////                            echo "Max: ".$max_id['id_new'];
//                            $mx = $max_id['id_new'];
////                            echo ",  mx: ".(int)$mx;
//                            $mx = (int)$mx+1;
////                            echo ",  mx: ".$mx;
//                            $id_new = sprintf("%010d", $mx);
////                            echo $id_new;
//                        }
//                        
//                        $this->db->set('id_new', $id_new);
//                        $this->db->set('id_temple', '0010');
//                        $this->db->set('headnews', $headnews);
//                        $this->db->set('headline', $headline);
//                        $this->db->set('detail', $detail);
//                        $this->db->set('pic_news', $headnews);
//                        $this->db->set('date', date('Y-m-d'));
//                        $this->db->set('linkurl', $linkurl);
//                        $this->db->insert('news');
//
//			$this->load->view('backend/admin/admin', $data);
//		}
////                            }
//                }else if($value1=="update"){
//                    $this->load->view("backend/admin/$file",$data);                        
//                }
////                $data['key']       = $value;
////                $data['select_menu']    = $value1;
////                $this->load->view("backend/admin/$file",$data);                
//            }else if($file=="login")
//            {                
//                $data['key']       = $value;
//                $data['login']    = true;
//                $this->load->view("backend/admin/$file",$data);                
//            }
//            else 
//            if($file=="logout")
//            {          
//                $data['key']       = $value;
//                $data['logout']    = true;
//                $this->load->view("backend/admin/$file",$data);                
//            }
//            $this->load->view("template_u/template_u_footer");            
//        }     
        public function register($file)
        {       
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            if($file=='forget_pwd')
            {
                if(!isset($_POST['user_login']))
                {
                    $this->load->view("fontend/register/$file");
                }else
                {
                $data['user_login'] = $_POST['user_login'];                
                $data['forget'] = $_POST['forget'];
                $rs = $this->homepage_model->getMember($_POST['user_login']);
                $data['r']      = $rs->result_array();
                $data['r_num']  = $rs->num_rows();
                $this->load->view("fontend/register/$file",$data);
                }
            }else
            {
                $this->load->view("fontend/register/$file");
            }

            $this->load->view("template_u/template_u_footer");
        }
        public function homepage($file)
        {       
            $line_news = 10;
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $rs    = $this->homepage_model->getNews(0,$line_news);
            $data["r"]     = $rs->result_array();
            $this->load->view("fontend/homepage/$file",$data);
            $this->load->view("template_u/template_u_footer");
        }
        public function news($file)
        {
            $line_news = 20;
            $this->load->helper('html');
            if($file=="index"){
                $this->load->view("template_u/template_u_header");
                $rs    = $this->homepage_model->getNews(0,10);
                $data["r"]     = $rs->result_array();
                $this->load->view("fontend/news/$file",$data);
                $this->load->view("template_u/template_u_footer");   
            }else{
                $this->load->view("template_u/template_u_header");
                $rs     = $this->homepage_model->getReadNews($id);
                $data["r"]      = $rs->result_array();
                $this->load->view("fontend/news/$file",$data);
                $this->load->view("template_u/template_u_footer"); 
            }

            $this->load->view("template_u/template_u_header");
            $rs    = $this->homepage_model->getNews(0,$line_news);
            $data["r"]     = $rs->result_array();
            $this->load->view("fontend/news/$file",$data);
            $this->load->view("template_u/template_u_footer");
        }
        public function maps($file,$value)
        {
            $this->load->helper('html');
            $data['google_maps'] = $value;
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/maps/$file",$data);
            $this->load->view("template_u/template_u_footer");            
        }
        public function history($file)
        {
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/history/$file");
            $this->load->view("template_u/template_u_footer");            
        }
        public function contact($file)
        {
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/contact/$file");
            $this->load->view("template_u/template_u_footer");            
        }   
        public function knowledge($file)
        {       
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/knowledge/$file");
            $this->load->view("template_u/template_u_footer");
        }        
        public function introduction($file)
        {       
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/introduction/$file");
            $this->load->view("template_u/template_u_footer");
        }          
        public function webboard($file)
        {       
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/webboard/$file");
            $this->load->view("template_u/template_u_footer");
        }        
        public function gbook($file)
        {       
            $this->load->helper('html');
            $this->load->view("template_u/template_u_header");
            $this->load->view("fontend/gbook/$file");
            $this->load->view("template_u/template_u_footer");
        }
}
